package com.cby.leetcode.链表.LC206;

/**
 * ClassName: LC206
 * Package: com.cby.leetcode.链表.LC206.LC206
 * Description:
 *
 * @Author dhu-bion
 * @Create 2025/9/4 14:15
 * @Version 1.0
 */
public class LC206 {
    public static void main(String[] args){

        LC206.Solution solution = new Solution();
//
//        int[] numbers = new int[]{
//                2,7,11,15
//        };
//
//        Arrays.stream(solution.twoSum(numbers, 9)).forEach(System.out::println);

    }

    // 定义链表节点类
    static class ListNode {
        int val;
        ListNode next;
        ListNode() {}
        ListNode(int val) { this.val = val; }
        ListNode(int val, ListNode next) { this.val = val; this.next = next; }
    }

    static class Solution {
        public ListNode reverseList(ListNode head) {
            ListNode prev = null;
            ListNode current = head;

            while(current != null){
                //存储下一个位置
                ListNode next = current.next;
                //尾头互换
                current.next = prev;
                prev = current;

                current = next;
            }

            return prev;
        }
    }
}
